package com.gvfish.backingbean.admin;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import net.sf.dozer.util.mapping.DozerBeanMapper;

import org.springframework.context.ApplicationContext;
import org.springframework.web.jsf.FacesContextUtils;

import com.gvfish.core.DozerBeanMapperFactory;
import com.gvfish.entity.Category;
import com.gvfish.service.CategoryManager;

@ManagedBean
@RequestScoped
public class CategoryInput {
	ApplicationContext ctx = FacesContextUtils
			.getWebApplicationContext(FacesContext.getCurrentInstance());
	CategoryManager categoryManager = (CategoryManager) ctx
			.getBean("categoryManager");
	private Long parentId;
	private String name;// 分类名称
	private String description;// 分类描述
	private String metaTitle;
	private String metaKeyWords;
	private String metaDescription;

	public String submit() {
		Category category = new Category();
		DozerBeanMapper mapper = DozerBeanMapperFactory.getMapper();
		mapper.map(this, category);
		System.out.println(category);
		categoryManager.save(category, parentId);
		return "/";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getMetaTitle() {
		return metaTitle;
	}

	public void setMetaTitle(String metaTitle) {
		this.metaTitle = metaTitle;
	}

	public String getMetaKeyWords() {
		return metaKeyWords;
	}

	public void setMetaKeyWords(String metaKeyWords) {
		this.metaKeyWords = metaKeyWords;
	}

	public String getMetaDescription() {
		return metaDescription;
	}

	public void setMetaDescription(String metaDescription) {
		this.metaDescription = metaDescription;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public Long getParentId() {
		return parentId;
	}

}
